import datetime
import random
from functools import reduce

from manager.app import db
from manager.app.device.model import Action

class RobotServiceWorker(object):
    def __init__(self, device):
        # service machine id
        self._device = device

    def get_app_list(self):
        '''

        :return: []
        '''
        pass

    def delete_app(self, app_name):
        '''

        :return:
        '''
        pass

    def get_robot_list(self, *args, **kwargs):
        '''

        :param args:
        :param kwargs:
        :return: []
        '''
        return NotImplementedError

    def get_daemon_status(self):
        return NotImplementedError

    def get_job_list(self, project_name, robot_status):
        '''

        :param project_name:
        :param robot_status:
        :return: job service execution id list
        '''
        return NotImplementedError

    def start_robot(self, *args, **kwargs):
        '''

        :param args:
        :param kwargs:
        :return: {id:foo,start_time:None,end_time:None}
        '''
        return NotImplementedError

    def cancel_robot(self, *args, **kwargs):
        return NotImplementedError

    def deploy(self, *args, **kwargs):
        pass

    def log_url(self, *args, **kwargs):
        pass

    @property
    def device(self):
        return self._device


class Worker():
    def __init__(self):
        self.robot_service_instances = []

    def regist(self, deviceWorker):
        if isinstance(deviceWorker, RobotServiceWorker):
            self.robot_service_instances.append(deviceWorker)

    def get_action_list(self):
        action_list = self.robot_service_instances[0].get_action_list()
        return [action.to_dict() for action in Action.query.all()]


    @property
    def servers(self):
        return [self.robot_service_instance.server for self.robot_service_instance in
                self.robot_service_instances]


if __name__ == '__main__':
    pass
